<?php
	   header('Content-Type:text/html;charset=utf-8');
	   include './Model.php';
	   echo '<pre>';
	 /***************根据新数据表的字段从老表中查询出对应字段的数据***************
	   $conn =new Mysql ('preferredshares','oc_admin_user');
	   $sql = 'select id, user_type,avatar as avatar_img ,province,city,town as district,nickname as nick_name,username as user_name,password as user_password,truename as true_name,sex, mobile,idcard as id_card ,unionid as wx_union_id, openid1 as wx_open_id ,recommender as recommend_user ,recommendedphone as recommend_mobile ,create_time,update_time from  oc_admin_user ;';
	  ****************************************************************************
	  ********根据你新表字段从老表中查询出对应字段********************************
	   $conn =new Mysql('preferredshares','oc_user_org');
	   $sql ='select type ,uid as client_id ,create_time as confirm_time, parent_id as parent_cid, m.id as management_id from  oc_user_org as o left join client_management as m on  uid_id =m.client_id  having type=3';
	   echo '<pre>';
	   $res=$conn->getAll($sql);
	   //var_dump($res);
	   //exit;
	  ****************************************************************************
	  */
	   /*$conn =new Mysql('preferredshares','oc_user_org');
       
       $sql  = 'select type, uid as client_id ,parent_id as parent_cid, equity , createtime as create_time ,ic.id as init_comp_id, ic.management_id as management_id from oc_user_org left join client_initiator_company as ic on parent_id = ic.client_id having type=4;'; 

       $res =$conn->getAll($sql);
       var_dump($res);
       exit;
          
	 
       $conn =new Mysql('preferredshares','oc_user_org');
	   $sql ='select type ,uid as client_id ,equity_time as confirm_time, createtime as create_time ,parent_id as parent_cid, m.id as management_id 
	   from  oc_user_org as o 
	   left join client_management as m on  uid =m.client_id  
	   having type=3';
	   echo '<pre>';
	   $res=$conn->getAll($sql);
	   //var_dump($res);
	   //exit;
	   */
       /*
	   $conn =new Mysql('preferredshares','oc_user_org');
       
       $sql  = 'select type, uid as client_id ,parent_id as parent_cid, equity , createtime as create_time ,equity_time as confirm_time,ic.id as init_comp_id, cm.id as management_id 
       from oc_user_org as o 
       left join client_initiator_company as ic on uid = ic.client_id 
       left join client_management        as cm on  o.uid = cm.client_id 
       having type=4;'; 
       $res =$conn->getAll($sql);
       //var_dump($res);
       //exit;
     
       */
        /*
        $conn =new Mysql('preferredshares','oc_user_org');
       
       $sql  = 'select type, uid as client_id ,parent_id as parent_cid, equity , certificate, createtime as create_time ,equity_time as confirm_time,ic.id as init_comp_id, cm.id as management_id ,cp.id as partner_id
       from oc_user_org as o 
       left join client_initiator_company as ic on o.uid = ic.client_id 
       left join client_management        as cm on o.uid = cm.client_id
	   left join client_partner           as cp on o.uid = cp.client_id 
       having type=5'; 
       $res =$conn->getAll($sql);
       //var_dump($res);
       //exit;
       */
       /*
       $conn =new Mysql('preferredshares','oc_user_org');
       
       $sql  = 'select type, uid as client_id ,parent_id as parent_cid, equity , certificate, createtime as create_time ,equity_time as confirm_time,ic.id as init_comp_id, cm.id as management_id ,cp.id as partner_id,
       cf.id as planner_id from oc_user_org as o 
       left join client_financial_planner as cf on o.uid = cf.client_id
       left join client_initiator_company as ic on o.uid = ic.client_id 
       left join client_management        as cm on o.uid = cm.client_id
	   left join client_partner as cp on o.uid = cp.client_id 
       having type=6 ';
       $res =$conn->getAll($sql);
       //var_dump($res);
       //exit;
       */
       /*
       $conn =new Mysql('preferredshares','oc_user_org');
	   $sql ='select type ,uid as client_id ,equity_time as confirm_time, createtime as create_time ,parent_id as parent_cid, m.id as management_id 
	   from  oc_user_org as o left join client_management as m on  uid =m.client_id  
	   having type in (1,2)';
	   echo '<pre>';
	   $res=$conn->getAll($sql);
	   // var_dump($res);
	   //exit;
	   */
	    $conn =new Mysql ('preferredshares','oc_admin_user');
	    $sql = 'select id, user_type,avatar as avatar_img ,province,city,town as district,nickname as nick_name,username as user_name,password as user_password,truename as true_name,sex, mobile,idcard as id_card ,unionid as wx_union_id, openid1 as wx_open_id ,recommender as recommend_user ,recommendedphone as recommend_mobile ,create_time,update_time from  oc_admin_user ;';
	    echo '<pre>';
	    $res=$conn->getAll($sql);
	    //var_dump($res);
	    //exit;
	    $conn1 =  new Mysql('school','client_info'); 
		   foreach ($res as $k =>$v){
		        $data =array();
		     /*  *******用户信息存入表************************************************ */
		        $data['id']=$v['id'];
		        $data['user_type']=$v['user_type'];
		        $data['avatar_img']=$v['avatar_img'];
		        $data['province']=$v['province'];
		        $data['city']=$v['city'];
		        $data['district']=$v['district'];
		        $data['nick_name']=addslashes($v['nick_name']);
		        $data['true_name']=$v['true_name'];
		        $data['user_name']=$v['user_name'];
		        $data['user_password']=$v['user_password'];
		        $data['sex']=$v['sex'];
		        $data['mobile']=$v['mobile'];
		        $data['id_card']=$v['id_card'];
		        $data['wx_union_id']=$v['wx_union_id'];
		        $data['wx_open_id']=$v['wx_open_id'];
		        $data['recommend_user']=$v['recommend_user'];
		        $data['recommend_mobile']=$v['recommend_mobile'];
		        $data['create_time']=date('Y-m-d H:i:s',$v['create_time']);
		        $data['update_time']=$v['update_time']==0 ? 'null':date('Y-m-d H:i:s',$v['update_time']);
		        echo '<pre>';
		        var_dump($data);
		        $res=$conn1->insert($data);

		       
		        /*
		        **************管理机构人员信息表****************************************
		        $data['client_id']=$v['client_id'];
		        $data['management_name']=$v['management_name'];
		        $data['client_id']=$v['client_id'];
		        $data['create_time']=$v['create_time'];
		        $res=$conn1->insert($data);

		        **************发起人人员信息表****************************************
		        */ 
		        /*
		        $data['client_id'] =$v['client_id'];
		        $data['confirm_time'] =date('Y-m-d H:i:s',$v['confirm_time']);
		        $data['parent_cid'] =$v['parent_cid'];
		        $data['management_id'] =$v['management_id'];
		        $data['is_management'] =isset($v['management_id'])?1:0;
		        $data['create_time']  =date('Y-m-d H:i:s',$v['create_time']);
                $res=$conn1->insert($data);
   
                */
                
                /*
                $data['client_id'] =$v['client_id'];
                //$data['parent_cid'] =$v['parent_cid'];
                $data['is_investor'] =$v['certificate']==Null ? 0 : 1;
                $data['is_qualified'] =$v['equity']==Null ? 0 : 1;
                $data['create_time']  =date('Y-m-d H:i:s',$v['create_time']);
                $data['confirm_time']  =date('Y-m-d H:i:s',$v['confirm_time']);
                $data['planner_id']   =$v['planner_id'];
                $data['partner_id']   =$v['partner_id'];
                $data['init_comp_id'] = $v['init_comp_id'];
                $data['management_id'] = $v['management_id']; 
                $res=$conn1->insert($data);
                */
		   }

   